package com.xhwl.logistics.converter;

import com.xhwl.logistics.bo.VehicleAccessRecordStatisticsBO;
import com.xhwl.logistics.bo.VehicleAccessRecordStatisticsDateBO;
import com.xhwl.logistics.vo.VehicleAccessRecordStatisticsVO;
import com.xhwl.logistics.vo.VehicleStatisticsDateVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class ToVehicleAccessRecordStatisticsVO {

    public VehicleAccessRecordStatisticsVO toVehicleStatisticsVO(VehicleAccessRecordStatisticsBO vehicleAccessRecordStatisticsBO, Integer type) {
        VehicleAccessRecordStatisticsVO vehicleAccessRecordStatisticsVO = new VehicleAccessRecordStatisticsVO();

        BeanUtils.copyProperties(vehicleAccessRecordStatisticsBO, vehicleAccessRecordStatisticsVO, "enter", "exist");

        List<VehicleStatisticsDateVO> enter = vehicleAccessRecordStatisticsBO.getEnter().stream().map(VehicleAccessRecordStatisticsDateBO::toVehicleStatisticsDateVO).collect(Collectors.toList());
        List<VehicleStatisticsDateVO> exist = vehicleAccessRecordStatisticsBO.getExist().stream().map(VehicleAccessRecordStatisticsDateBO::toVehicleStatisticsDateVO).collect(Collectors.toList());

//        List<VehicleStatisticsDateVO> enter = vehicleAccessRecordStatisticsBO.getEnter().stream().map(vehicleStatisticsDateBO -> {
//            VehicleStatisticsDateVO vehicleStatisticsDateVO = new VehicleStatisticsDateVO();
//            if (type.equals(0)) {
//                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//                String stringDate = dateTimeFormatter.format(ZonedDateTime.ofInstant(vehicleStatisticsDateBO.getDate().toInstant(), ZoneId.of(VehicleConstant.vehicleTimeZone)));
//
//                vehicleStatisticsDateVO.setDate(stringDate);
//                vehicleStatisticsDateVO.setCount(vehicleStatisticsDateBO.getCount());
//            }
//            if (type.equals(1)) {
//                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//                String stringDate = dateTimeFormatter.format(ZonedDateTime.ofInstant(vehicleStatisticsDateBO.getDate().toInstant(), ZoneId.of(VehicleConstant.vehicleTimeZone)));
//
//                vehicleStatisticsDateVO.setDate(stringDate);
//                vehicleStatisticsDateVO.setCount(vehicleStatisticsDateBO.getCount());
//            }
//            if (type.equals(2)) {
//                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//                String stringDate = dateTimeFormatter.format(ZonedDateTime.ofInstant(vehicleStatisticsDateBO.getDate().toInstant(), ZoneId.of(VehicleConstant.vehicleTimeZone)));
//
//                vehicleStatisticsDateVO.setDate(stringDate);
//                vehicleStatisticsDateVO.setCount(vehicleStatisticsDateBO.getCount());
//            }
//            if (type.equals(3)) {
//                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
//                String stringDate = dateTimeFormatter.format(ZonedDateTime.ofInstant(vehicleStatisticsDateBO.getDate().toInstant(), ZoneId.of(VehicleConstant.vehicleTimeZone)));
//
//                vehicleStatisticsDateVO.setDate(stringDate);
//                vehicleStatisticsDateVO.setCount(vehicleStatisticsDateBO.getCount());
//            }
//            if (type.equals(-1)) {
//                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//                String stringDate = dateTimeFormatter.format(ZonedDateTime.ofInstant(vehicleStatisticsDateBO.getDate().toInstant(), ZoneId.of(VehicleConstant.vehicleTimeZone)));
//
//                vehicleStatisticsDateVO.setDate(stringDate);
//                vehicleStatisticsDateVO.setCount(vehicleStatisticsDateBO.getCount());
//            }
//            return vehicleStatisticsDateVO;
//        }).collect(Collectors.toList());
//
//        List<VehicleStatisticsDateVO> exist = vehicleAccessRecordStatisticsBO.getExist().stream().map(vehicleStatisticsDateBO -> {
//            VehicleStatisticsDateVO vehicleStatisticsDateVO = new VehicleStatisticsDateVO();
//            if (type.equals(0)) {
//                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//                String stringDate = dateTimeFormatter.format(ZonedDateTime.ofInstant(vehicleStatisticsDateBO.getDate().toInstant(), ZoneId.of(VehicleConstant.vehicleTimeZone)));
//
//                vehicleStatisticsDateVO.setDate(stringDate);
//                vehicleStatisticsDateVO.setCount(vehicleStatisticsDateBO.getCount());
//            }
//            if (type.equals(1)) {
//                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//                String stringDate = dateTimeFormatter.format(ZonedDateTime.ofInstant(vehicleStatisticsDateBO.getDate().toInstant(), ZoneId.of(VehicleConstant.vehicleTimeZone)));
//
//                vehicleStatisticsDateVO.setDate(stringDate);
//                vehicleStatisticsDateVO.setCount(vehicleStatisticsDateBO.getCount());
//            }
//            if (type.equals(2)) {
//                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//                String stringDate = dateTimeFormatter.format(ZonedDateTime.ofInstant(vehicleStatisticsDateBO.getDate().toInstant(), ZoneId.of(VehicleConstant.vehicleTimeZone)));
//
//                vehicleStatisticsDateVO.setDate(stringDate);
//                vehicleStatisticsDateVO.setCount(vehicleStatisticsDateBO.getCount());
//            }
//            if (type.equals(3)) {
//                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
//                String stringDate = dateTimeFormatter.format(ZonedDateTime.ofInstant(vehicleStatisticsDateBO.getDate().toInstant(), ZoneId.of(VehicleConstant.vehicleTimeZone)));
//
//                vehicleStatisticsDateVO.setDate(stringDate);
//                vehicleStatisticsDateVO.setCount(vehicleStatisticsDateBO.getCount());
//            }
//            if (type.equals(-1)) {
//                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//                String stringDate = dateTimeFormatter.format(ZonedDateTime.ofInstant(vehicleStatisticsDateBO.getDate().toInstant(), ZoneId.of(VehicleConstant.vehicleTimeZone)));
//
//                vehicleStatisticsDateVO.setDate(stringDate);
//                vehicleStatisticsDateVO.setCount(vehicleStatisticsDateBO.getCount());
//            }
//            return vehicleStatisticsDateVO;
//        }).collect(Collectors.toList());

        vehicleAccessRecordStatisticsVO.setEnter(enter);
        vehicleAccessRecordStatisticsVO.setExist(exist);

        return vehicleAccessRecordStatisticsVO;
    }

}
